// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import VCharts from 'v-charts'
import 'element-ui/lib/theme-chalk/index.css'
import 'babel-polyfill'
import './assets/css/main.css'
import store from './store'

Vue.use(ElementUI)
Vue.use(VCharts)

router.beforeEach((to, from, next) => {
  console.log('requireAuth => ' + to.meta['requireAuth'])
  if (to.meta['requireAuth']) {
    if (localStorage.getItem('SaToken') && localStorage.getItem('SaToken') !== null) {
      next()
    } else {
      next({
        path: '/',
        query: {redirect: to.fullPath}
      })
    }
  } else {
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
